package com.sunyy.codegenerator.config.freemarker;

import freemarker.template.TemplateExceptionHandler;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author sunyy
 * @date 2025/7/10
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "free-marker")
public class FreeMarkerConfig {

    /**
     * 模板存储路径
     */
    private String templatePath;

    /**
     * 输出路径
     */
    private String outputPath;

    /**
     * 允许的MIME类型
     */
    private String allowMimeType;

    @Bean("freeMarkerTemplateConf")
    public freemarker.template.Configuration getFreeMarkerTemplateConf() {
        freemarker.template.Configuration cfg = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_22);
        MyByteArrayTemplateLoader loader = new MyByteArrayTemplateLoader();
        cfg.setTemplateLoader(loader);
        cfg.setDefaultEncoding("UTF-8");
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
        return cfg;
    }
}
